package com.sproutcat.sample;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
@Slf4j
public class CustomCacheService {

    @Cacheable(value = "test:uuid#10")
    public String getById(Long id) {
        UUID uuid = UUID.randomUUID();
        log.info("getById: {} - {}", id, uuid);
        return uuid.toString();
    }

    @CachePut(value = "test:uuid#5")
    public String updateById(Long id) {
        UUID uuid = UUID.randomUUID();
        log.info("updateById: {} - {}", id, uuid);
        return uuid.toString();
    }

    @Cacheable(value = "test:uuid#10#1")
    public String getNull(Long id) {
        log.info("getNull: {}", id);
        return null;
    }

    @CacheEvict(value = "test:uuid")
    public void deleteById(Long id) {
        log.info("deleteById: {}", id);
    }

    @CacheEvict(value = "test:uuid", allEntries = true)
    public void deleteAll() {
        log.info("deleteAll");
    }

}
